import json

def get_stored_username():
    '''如果储存了用户名，就获取它'''
    filename = 'username.json'
    try:
        with open(filename) as f:
            username = json.load(f)
    except Exception:
        return None
    else:  # try执行成功后执行的代码块
        return username

def get_new_username():
    '''提示用户输入用户名'''
    username = input('What is you name?')
    filename = 'username.json'
    with open(filename, 'a') as f:
        json.dump(username, f)
    return username

def greet_user():
    '''问候用户，并指出其名字'''
    username = get_stored_username()
    if username:
        print(f"Welcome back,{username.title()}!")
    else:
        username = get_new_username()
        print(f"We will remember you when you come back,{username.title()}!")

greet_user()

